package com.lew.springboot.mybatis.demo.controller;

import com.lew.springboot.mybatis.demo.entity.User;
import com.lew.springboot.mybatis.demo.service.UserService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.Resource;

@Controller
@RequestMapping("user")
public class UserController {

    private AtomicInteger count = new AtomicInteger();

    @Resource
    private UserService userService;

    @RequestMapping("add")
    public void add(){
        User user = new User();
        Integer num = count.incrementAndGet();
        user.setName("test"+num);
        user.setCreateTime(new Date());
        user.setId(String.valueOf(num));
        userService.add(user);
    }

    @RequestMapping("list")
    @ResponseBody
    public List<User> list(){
        return userService.getList();
    }
}
